﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Manager
{
    public partial class AddCV : Form
    {
        SQL sql = new SQL();
       private string MCT;
       private string NAMECT;
        //string MCV;
       private string MPB;
        public AddCV()
        {
            InitializeComponent();
        }

        private void AddCV_Load(object sender, EventArgs e)
        {
            getMCV();
        }
        public AddCV(string @MCT, string @NAMECT, string @MPB):this()
        {
            this.MCT=@MCT;
            textBox1.Text=MCT;
            this.NAMECT = @NAMECT;
            textBox2.Text = NAMECT;
            this.MPB = @MPB;
            textBox3.Text = MPB;
        }
        private void getMCV()
        {
            string query = "sql_MCV_cb";
            comboBox1.DataSource = sql.getDataTable(query);
            comboBox1.ValueMember = "MCV";

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string query = "sql_update_CongViec";
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter("@MCT", textBox1.Text);
            pr[1] = new SqlParameter("@MCV", comboBox1.Text.Trim());
            sql.execute_Query(query, pr);
            MessageBox.Show("Insert successful!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();            
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            string query = "sql_NAMECV_where_MCV";
            dt = sql.getDataTable(query, new SqlParameter("@MCV", comboBox1.Text.Trim()));
            if (dt.Rows.Count > 0)
            {
                textBox4.Text= dt.Rows[0][0].ToString();
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
       

    }
}
